package com.ruoyi.college.controller;

import java.util.List;

import com.ruoyi.college.domain.Course;
import com.ruoyi.college.domain.Semester;
import com.ruoyi.college.domain.Teacher;
import com.ruoyi.college.service.ICourseService;
import com.ruoyi.college.service.ISemesterService;
import com.ruoyi.college.service.ITeacherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.college.domain.CourseArrangement;
import com.ruoyi.college.service.ICourseArrangementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程安排主Controller
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@Controller
@RequestMapping("/college/arrangement")
public class CourseArrangementController extends BaseController
{
    private String prefix = "college/arrangement";

    @Autowired
    private ICourseArrangementService courseArrangementService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private ISemesterService semesterService;

    @Autowired
    private ITeacherService teacherService;

    @RequiresPermissions("college:arrangement:view")
    @GetMapping()
    public String arrangement(ModelMap mmap)
    {
        //课程包课程
        mmap.put("courses",courseService.selectCourseList(new Course()));
        mmap.put("semesters",semesterService.selectSemesterList(new Semester()));
        mmap.put("teachers",teacherService.selectTeacherList(new Teacher()));
        return prefix + "/arrangement";
    }

    /**
     * 查询课程安排主列表
     */
    @RequiresPermissions("college:arrangement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseArrangement courseArrangement)
    {
        startPage();
        List<CourseArrangement> list = courseArrangementService.selectCourseArrangementList(courseArrangement);
        return getDataTable(list);
    }

    /**
     * 导出课程安排主列表
     */
    @RequiresPermissions("college:arrangement:export")
    @Log(title = "课程安排主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseArrangement courseArrangement)
    {
        List<CourseArrangement> list = courseArrangementService.selectCourseArrangementList(courseArrangement);
        ExcelUtil<CourseArrangement> util = new ExcelUtil<CourseArrangement>(CourseArrangement.class);
        return util.exportExcel(list, "课程安排主数据");
    }

    /**
     * 新增课程安排主
     */
    @RequiresPermissions("college:arrangement:add")
    @GetMapping("/add")
    public String add(ModelMap  mmap)
    {
        mmap.put("courses",courseService.selectCourseList(new Course()));
        mmap.put("semesters",semesterService.selectSemesterList(new Semester()));
        mmap.put("teachers",teacherService.selectTeacherList(new Teacher()));
        return prefix + "/add";
    }

    /**
     * 新增保存课程安排主
     */
    @RequiresPermissions("college:arrangement:add")
    @Log(title = "课程安排主", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseArrangement courseArrangement)
    {
        return toAjax(courseArrangementService.insertCourseArrangement(courseArrangement));
    }

    /**
     * 修改课程安排主
     */
    @RequiresPermissions("college:arrangement:edit")
    @GetMapping("/edit/{arrangementId}")
    public String edit(@PathVariable("arrangementId") Long arrangementId, ModelMap mmap)
    {
        mmap.put("courses",courseService.selectCourseList(new Course()));
        mmap.put("semesters",semesterService.selectSemesterList(new Semester()));
        mmap.put("teachers",teacherService.selectTeacherList(new Teacher()));
        CourseArrangement courseArrangement = courseArrangementService.selectCourseArrangementByArrangementId(arrangementId);
        mmap.put("courseArrangement", courseArrangement);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程安排主
     */
    @RequiresPermissions("college:arrangement:edit")
    @Log(title = "课程安排主", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseArrangement courseArrangement)
    {
        return toAjax(courseArrangementService.updateCourseArrangement(courseArrangement));
    }

    /**
     * 删除课程安排主
     */
    @RequiresPermissions("college:arrangement:remove")
    @Log(title = "课程安排主", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseArrangementService.deleteCourseArrangementByArrangementIds(ids));
    }
}
